package homework;

import java.util.LinkedList;
import java.util.List;




class my_node{
    TreeNode node;
    int depth;
    int pos;
    public my_node(TreeNode node,int depth,int pos){
        this.node=node;
        this.depth=depth;
        this.pos=pos;
    }
}
public class HomeWork33 {
    public boolean isCompleteTree(TreeNode root) {
        int i=0;
        my_node node1=new my_node(root,1,1);
        List<my_node> list=new LinkedList();
        list.add(node1);
        while(list.size()>i){
            my_node node2=list.get(i++);
            if(node2.node!=null){
                list.add(new my_node(node2.node.left,node2.depth+1,2*node2.pos));
                list.add(new my_node(node2.node.right,node2.depth+1,2*node2.pos+1));
            }
        }
        return list.size()==list.get(list.size()-1).pos;
    }
}